package org.apache.lucene.ocean;

import java.util.List;

/**
 * Object returned by the update index methods of TransactionSystem.  
 *
 */
public class CommitResult {
  private Snapshot snapshot;
  private List<IndexSnapshotCommitResult> deletesResults;
  private Integer numAdded;
  private IndexID addedIndexId;
  private int numDeleted = 0;
  private List<Long> documentIds;

  public CommitResult(Snapshot snapshot, List<Long> documentIds, List<IndexSnapshotCommitResult> deletesResults, Integer numAdded, IndexID addedIndexId) {
    this.snapshot = snapshot;
    this.documentIds = documentIds;
    this.deletesResults = deletesResults;
    this.numAdded = numAdded;
    this.addedIndexId = addedIndexId;
    if (deletesResults != null) {
      for (IndexSnapshotCommitResult deletesResult : deletesResults) {
        numDeleted += deletesResult.getNumDeleted();
      }
    }
  }
  
  public String toString() {
    return "numAdded: "+numAdded+" numDeleted: "+numDeleted;
  }
  
  public List<Long> getDocumentIds() {
    return documentIds;
  }
  
  public Snapshot getSnapshot() {
    return snapshot;
  }
  
  public int getNumDeleted() {
    return numDeleted;
  }
  
  public int getNumDocChanges() {
    int numChanged = 0;
    if (numAdded != null)
      numChanged += numAdded;
    if (deletesResults != null) {
      for (IndexSnapshotCommitResult deletesResult : deletesResults) {
        numChanged += deletesResult.getNumDeleted();
      }
    }
    return numChanged;
  }

  public Long getSnapshotId() {
    return snapshot.getSnapshotId();
  }

  public List<IndexSnapshotCommitResult> getDeletesResults() {
    return deletesResults;
  }

  public Integer getNumAdded() {
    return numAdded;
  }

  public IndexID getAddedIndexId() {
    return addedIndexId;
  }
}
